<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<!--<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
-->
<script src="<?php echo URL::base() ?>media/laydate/laydate.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.form.3.51.0.js"></script>
<style>
    .xiangqing tbody tr td,.xiangqing tbody tr th{ border:1px solid #eee;}
    .xiangqing tbody tr td input{ width:100px;}
    .xiangqing tbody tr td select{ width:130px;}
    .xiangqing tbody tr td input.tijiao{ width:50px;}
    #txtHint{ position:absolute; top:30px; left:98px; display:none; background-color:#EDFAF4;min-width:281px; border:1px solid; border-radius:5px;height:150px;overflow:auto;border: 1px solid #aaa; padding:5px 2px;}
    #txtHint  li{ list-style:none; color:#333; border:1px solid #EDFAF4;padding: 0px 8px;}
    #txtHint  li:hover{  color:#c37100; background-color:#fdf8d5; border:1px solid #fac900; border-radius:25px;}
    #detail span:hover{ color:#c37100;}
    .table_t10{ margin-top: 20px;}
</style>

<form class="form-horizontal form-search" method="get" action="<?php echo URL::site('unqualified/unqualified_select');?>">
    <div class="control-group">
        <label class="control-label">是否库内:</label>
        <div class="controls">
            <select name="no_purchaseorder_id" >
                <option value="0" <?php if($no_purchaseorder_id == 0) {echo "selected = 'selected'";} ?>>请选择</option>
                <option value="20" <?php if($no_purchaseorder_id == 20) {echo "selected = 'selected'";} ?>>非库内</option>
                <option value="10" <?php if($no_purchaseorder_id == 10) {echo "selected = 'selected'";} ?>>库内</option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">计划员:</label>
        <div class="controls">
            <input  name="purchase_man_name"  type="text" value="<?php if(isset($_GET['purchase_man_name'])){ echo $_GET['purchase_man_name'];}?>" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">处理人:</label>
        <div class="controls">
            <input  name="operate_man"  type="text" value="<?php if(isset($_GET['operate_man'])){ echo $_GET['operate_man'];}?>" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">供应商:</label>
        <div class="controls">
            <input  name="supplier"   autocomplete="off" id="supplier_id" type="text" value="<?php if(isset($supplier)){ echo $supplier;}?>"  />
        </div>
        <div id="txtHint"   style="z-index:222px; margin-top:199px;margin-left:52px;overflow-x:hidden;"  ></div>
    </div>
    <div class="control-group">
        <label class="control-label">SKU:</label>
        <div class="controls">
            <input   name="sku" type="text" value="<?php if(isset($sku)){ echo $sku;}?>" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">VMI单号:</label>
        <div class="controls">
            <input   onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" name="purchaseorder_id" type="text" value="<?php if(isset($purchaseorder_id)){ echo $purchaseorder_id;}?>" />
        </div>
    </div>

    <div class="control-group">
        <label class="control-label">质检日期从:</label>
        <div class="controls">
            <input type="text"  class="input-medium" name="date_from" id="date_from" value="<?php if(isset($date_from)){ echo $date_from;}?>" />
            到
            <input name="date_to" class="input-medium"  type="text" id="date_to" value="<?php if(isset($date_to)){ echo $date_to;}?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">处理日期从:</label>
        <div class="controls">
            <input type="text" class="input-medium"  name="date_from_c" id="date_from_c" value="<?php if(isset($date_from_c)){ echo $date_from_c;}?>" />
            到
            <input name="date_to_c" class="input-medium"  type="text" id="date_to_c" value="<?php if(isset($date_to_c)){ echo $date_to_c;}?>"/>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label">状态:</label>
        <div class="controls">
            <select  name="status" id="status_choose">
                <option value="1"  >不合格产品处理:</option>
                <?php
                if(isset($sta)){
                    foreach($sta as $vs){

                        ?>
                        <option value="<?php echo $vs['number'];?>" <?php if(isset($status) && $status==$vs['number']){ echo 'selected="selected"';}?> ><?php echo $vs['value'];?></option>
                    <?php }}?>
            </select>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <button type="submit" class="btn btn-info" >查询</button>
            <a id="down" class="btn">下载</a>&nbsp;&nbsp;&nbsp;<span style="color: #ff0000">(量大时添加筛选条件后下载)</span>
        </div>
    </div>
</form>
<?php
if(isset($orm))
{
    foreach ($orm as $k=>$val)
    {
        ?>

        <table class="table table-hover table_t10">
            <thead>
            <tr>
                <th width="5%">序列</th>
                <th width="8%">计划员</th>
                <th width="12%">VMI预约单号</th>
                <th width="12%">质检明细单号</th>
                <th width="12%">SKU</th>
                <th width="12%">中文名称</th>
                <th width="12%">供应商</th>
            </tr>
            </thead>
            <tr>
                <td>
                    <?php echo  $k+1;?>
                </td>
                <td><?php if($val['purchaser']){echo $val['purchaser'];?>
                        <input  type="hidden" name="id" id="id_<?php echo $val['id'];?>" value="<?php echo $val['id'];?>"/>
                    <?php }else{?>
                        <label class="pu_man_input" style="color: #d3d3d3">双击修改</label>
                        <input type="hidden" value="<?php echo $val['id'];?>">
                    <?php }?>
                </td>
                <td>
                    <?php echo $val['purchaseorder_id'];?>
                    <input  type="hidden" name="purchaseorder_id" id="purchaseorder_<?php echo $val['id'];?>" value="<?php echo $val['purchaseorder_id'];?>"/>
                </td>

                <td>
                    <input  type="hidden" name="check_detail_id" id="check_<?php echo $val['id'];?>" value="<?php echo $val['check_detail_id'];?>"/>
                    <?php echo $val['check_detail_id'];?>
                </td>
                <td>
                    <?php echo $val['sku'];?>
                    <input  type="hidden" name="sku" id="sku_<?php echo $val['id'];?>" value="<?php echo $val['sku'];?>"/>
                </td>

                <td>
                    <?php echo $val['sku_name'];?>
                    <input  type="hidden" name="sku_name" id="sku_name_<?php echo $val['id'];?>" value="<?php echo $val['sku_name'];?>"/>
                </td>
                <td>
                    <?php if(isset($val['vProviderName'])&&$val['vProviderName']){?>
                        <?php echo $val['vProviderName'];//供应商?>
                        <input  type="hidden" name="vProviderName" id="vProviderName_<?php echo $val['id'];?>" value="<?php echo $val['vProviderName'];?>"/>
                    <?php }else{?>
                        <label class="su_input" style="color: #d3d3d3">双击修改</label>
                        <input type="hidden" value="<?php echo $val['id'];?>">
                    <?php }?>

                </td>

            </tr>
            <tr style="background-color:#f5f5f5;">
                <th>处理人</th>
                <th>质检人</th>
                <th>质检时间</th>
                <th>质检不合格原因</th>
                <th>状态</th>
                <th>不合格数量</th>
                <th>详情</th>
            </tr>
            <tr style="background-color:#ffffff;" >
                <td>
                    <!-- 换一个处理人 -->

                    <?php echo $val['operater'];//$val['operate_man'];?>

                </td>
                <td><?php echo $val['quality_man_name'];?></td>

                <td>
                    <?php echo $val['check_time'];?>
                </td>

                <td>
                    <?php echo $val['quality_remark']?>
                </td>

                <td>
                    <?php if($val['status']==10){echo '未处理';}elseif($val['status']==20){echo '已处理';}else{echo '完结处理';} ?>
                </td>


                <td>
                    <input  type="hidden" name="quantity" id="quantity_<?php echo $val['id'];?>" value="<?php echo $val['quantity'];?>"/>
                    <?php echo $val['quantity'];?>
                </td>

                <td>
                    <input type="button" value="详情" class="btn btn-info" onclick="chk_tr_display('a_<?php echo $val['id'];?>','b_<?php echo $val['id'];?>')" id="b_<?php echo $val['id'];?>"/>

                </td>
            </tr>
            <tr style="display:none" id="a_<?php echo $val['id'];?>">

                <td colspan="7">
                    <table class="xiangqing table">
                        <tr style="background-color:#f5f5f5;">
                            <th>序号</th>
                            <th id="qt_<?php echo $val['id'];?>">数量</th>
                            <th>处理方式</th>
                            <th>采购处理备注</th>
                            <th>运费</th>
                            <th>单价</th>
                            <th>采购处理日期</th>
                            <th>管理员处理结果</th>
                            <th><?php if($val['status']!=30){?><button class="btn btn-info addproduct" type="button"  id="addproduct_<?php echo $val['id'];?>">添加处理条数</button><?php }?></th>
                        </tr>
                        <?php
                        $bad=qualitycomm::select_bad_product_delivery_byid($val['id']);
                        if(!empty($bad))
                        {

                            $i=0;
                            foreach($bad as $k=>$v)
                            {
                                $i++;
                                ?>
                                <tr>

                                    <td>
                                        <?php echo $k+1;?>
                                    </td>

                                    <td>
                                        <input type="hidden" value="<?php echo $v['id'];?>" id="bad_<?php echo $val['id']; ?>_<?php echo  1000+$k+1;?>"/>
                                        <?php
                                        if( $v['status']==20)
                                        {
                                            echo $v['quantity'];
                                            ?>
                                            <input type="hidden" name="count[]" id="coun_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>" value="<?php echo $v['quantity'];?>"/>

                                            <?php
                                        }
                                        else
                                        {
                                        if($val['status']==30)
                                        {
                                            echo $v['quantity'];
                                        }
                                        else
                                        {

                                        ?>
                                        <input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"  name="count[]" id="coun_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>" value="<?php echo $v['quantity'];?>"/></td>
                                    <?php
                                    }
                                    }?>

                                    <td>
                                        <?php


                                        foreach($way as $ks=>$vl)
                                        {
                                            if($v['fail_deal_way']==$vl['number'])
                                            {
                                                $ways= $vl['value'];
                                                break;
                                            }
                                        }
                                        if( $v['status']==20)
                                        {

                                            echo $ways;
                                            ?>
                                            <input type="hidden" name="fail_deal_way[]" id="way_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>"  value="<?php echo $ways;?>"/>

                                            <?php
                                        }
                                        else
                                        {
                                            if($val['status']==30)
                                            {
                                                echo $ways;
                                            }
                                            else
                                            {
                                                ?>
                                                <select  id="way_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>"   name="fail_deal_way[]">
                                                    <option value="1000" >不合格处理方式</option>
                                                    <?php
                                                    foreach($way as $ks=>$vl)
                                                    {
                                                        ?>
                                                        <option value="<?php echo $vl['number'];?>" <?php if($v['fail_deal_way']==$vl['number']){?> selected="selected"<?php }?>><?php echo $vl['value'];?></option>
                                                    <?php }?>
                                                </select>
                                                <?php
                                            }
                                        }?>
                                    </td>

                                    <td>
                                        <?php
                                        if( $v['status']==20)
                                        {
                                            echo $v['unqualified_reason'];
                                            ?>
                                            <input type="hidden" id="remark_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>"   name="unqualified_reason[]" value="<?php echo $v['unqualified_reason'];?>"/>

                                            <?php

                                        }
                                        else
                                        {
                                            if($val['status']==30)
                                            {
                                                echo $v['unqualified_reason'];
                                            }
                                            else
                                            {
                                                ?>
                                                <input type="text" id="remark_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>"   name="unqualified_reason[]" value="<?php echo $v['unqualified_reason'];?>"/>
                                                <?php
                                            }
                                        }?>
                                    </td>
                                    <td><input type="text" id="return_cost_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>"   name="return_cost[]" value="<?php echo $v['return_cost'];?>"/></td>
                                    <td><input type="text" id="coupon_price_<?php echo $val['id'];?>_<?php echo  1000+$k+1;?>"   name="coupon_price[]" value="<?php echo $v['coupon_price'];?>"/></td>
                                    <td> <?php echo $v['deal_time'];?></td>
                                    <td> <?php echo $v['warehouse_remark'];?></td>
                                    <td> &nbsp;</td>
                                </tr>

                                <?php
                            }
                        }
                        else
                        {
                            ?>
                            <tr>

                                <td>
                                    1
                                </td>

                                <td>
                                    <input type="hidden" value="0" id="bad_<?php echo $val['id'];?>_1001"/>
                                    <input type="text" name="count[]" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"  id="coun_<?php echo $val['id'];?>_1001" value=""/></td>
                                <!-- 处理方式 -->
                                <td><select  id="way_<?php echo $val['id'];?>_1001"  name="fail_deal_way[]">
                                        <option value="1000" >不合格处理方式</option>
                                        <?php
                                        foreach($way as $ks=>$vl)
                                        {
                                            ?>
                                            <option value="<?php echo $vl['number'];?>"><?php echo $vl['value'];?></option>
                                        <?php }?>
                                    </select></td>

                                <td><input type="text" id="remark_<?php echo $val['id'];?>_1001"   name="unqualified_reason[]" value=""/></td>
                                <td><input type="text" id="return_cost_<?php echo $val['id'];?>_1001"   name="return_cost[]" value=""/></td>
                                <td><input type="text" id="coupon_price_<?php echo $val['id'];?>_1001"   name="coupon_price[]" value=""/></td>

                                <td> &nbsp;</td>
                                <td> &nbsp;</td>
                                <td> &nbsp;</td>
                            </tr>

                            <?php

                        }
                        ?>

                        <tbody id="productlists_<?php echo $val['id'];?>">
                        </tbody>
                        <tr>
                            <td>
                                <span id="co_<?php echo $val['id'];?>" style="display:none;"><?php if(isset($i)){ echo $i;unset($i);}else{echo 1;}?></span>
                                <?php if($val['status']!=30){?>
                                    <input type="button"   value="提交" id="submit_<?php echo $val['id'];?>" class="tijiao btn btn-info"/>
                                <?php }?>
                            </td>
                        </tr>
                    </table>


                </td>

            </tr>
            <tr>
            </tr>
        </table>
        <?php
    }
}?>

<?php if(isset($page_links)){echo $page_links;}?>

<script type="text/javascript">
    function chk_tr_display(tr,a)
    {
        if
        (document.getElementById(tr).style.display=='none')
        {
            document.getElementById(tr).style.display='';
            document.getElementById(a).innerHTML='收起';
        }
        else
        {
            document.getElementById(tr).style.display='none';
            document.getElementById(a).innerHTML='展开';
        }
    }
</script>
<script type="text/javascript"><!--

    $(document).ready(function() {
        laydate.render({
            elem: '#date_from'
        });
        laydate.render({
            elem: '#date_to'
        });
        laydate.render({
            elem: '#date_from_c'
        });
        laydate.render({
            elem: '#date_to_c'
        });

        $(".addproduct").click(function(){
            ids=$(this).attr('id');
            var lengs=ids.length;
            var id=ids.substr(11,lengs-11);//产品的ID
            var shu=parseInt($("#quantity_"+id).val());
            var co = parseInt($("#co_"+id).text());
            //alert(co);
            if(co >= shu)
            {
                $(this).css('display','none');
            }
            else{
                var count_id=id+'_'+parseInt(co+1001);

                //alert(count_id);//return;

                var table = '<tr id="tr_'+count_id+'">';
                table +='<td>'+parseInt(co+1)+'</td>';
                table += '<td><input type="hidden" style="width:100px;" value="0" id="bad_'+count_id+'"/><input style="width:100px;" type="text" placeholder="" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"  name="count[]" value="" id="coun_'+count_id+'"/></td>';
                table += '<td><select style="width:130px;"  id="way_'+count_id+'"  name="fail_deal_way[]">';
                table +='<option value="1000" >不合格处理方式</option>';
                table += '<?php foreach($way as $ks=>$v){ ?><option value="<?php echo $v['number'];?>" ><?php echo $v['value'];?></option><?php }?>';
                table +='</select></td>';
                table += '<td><input type="text" style="width:100px;" id="remark_'+count_id+'" value="" name="unqualified_reason[]" /></td>';
                table += '<td><input type="text" id="return_cost_'+count_id+'" style="width:100px;"   name="coupon_price[]" value=""/></td>';
                table +=  ' <td><input type="text" id="coupon_price_'+count_id+'" style="width:100px;"   name="return_cost[]" value=""/></td>';

                //   table +='<td><input type="button" value="提交" id="submit_'+count_id+'" class="tijiao" onclick="test_kdw();"/></td>';
                table += '<td style="text-align:center;"><input class="btn btn-info del " type="button" id="delete_'+count_id+'" value="删除"/></td></tr>';

                $("#co_"+id).text(co+=1);
                $("#productlists_"+id).before(table);

            }
        });
        //动态的删除多余的表格行
        $(document).on('click', '.del', function(){
            var ids=$(this).attr('id').split('_');
            var  id='#tr_'+ids[1]+'_'+ids[2];
            $("#co_"+ids[1]).text($("#co_"+ids[1]).text()-1);
            $(id).remove();

        });


        //单击添加按钮后到不良品出库单
        $(".tijiao").click(function(){
            var ids=$(this).attr("id");//确认按钮的ID
            var lengs=ids.length;
            var id=ids.substr(7,lengs-7);//不良产品的ID
            var shu=parseInt($("#quantity_"+id).val());//不合格数量
            var co = parseInt($("#co_"+id).text());//有多少个输入框
            var check_detail_id=$("#check_"+id).val();//质检明细ID
            var sku=$("#sku_"+id).val();//SKU
            var sku_name=$("#sku_name_"+id).val();//SKU名称
            var vProviderName=$("#vProviderName_"+id).val();//供应商
            var purchaseorder_id=$("#purchaseorder_"+id).val();//采购单的ID
            var cou=0;//填写的不合格数量
            var remark = new Array(); //采购备注
            var way_zong=new Array();//不合格处理方式
            var quality_count=new Array();//分开处理的数量
            var chuli=new Array();
            var k=0;
            var rem=0;
            var wrong_msg='';
            for(var num=0;num<co;num++)
            {

                var id_num ="#coun_"+id+'_'+parseInt(1001+num);//alert(parseInt($(id_num).val()));
                var id_way = "#way_"+id+'_'+parseInt(1001+num);//不合格处理方式
                var id_remark = "#remark_"+id+'_'+parseInt(1001+num);
                var id_val=$(id_remark).val();
                var result=id_val?id_val.replace(/(^\s*)|(\s*$)/g,""):false;
                var id_coupon = "#coupon_price_"+id+'_'+parseInt(1001+num);
                var dan_price=  "#return_cost_"+id+'_'+parseInt(1001+num);
                var coupon_price= $(id_coupon).val();
                dan_price = $(dan_price).val();


                quality_count=parseInt($(id_num).val());
                way_zong=$(id_way).val();

                wrong_msg +=!quality_count?num+1+"行数量有误\n":'';
                wrong_msg +=!way_zong||way_zong==1000?num+1+"行处理方式不能为空\n":'';
                
                if(quality_count==0){
                    alert('第'+(num+1)+'行数量不能为0');return;
                }
                
                remark=result;
                var bad_id=$("#bad_"+id+'_'+parseInt(1001+num)).val();
                //alert(coupon_price);
                if(isNaN(parseInt($(id_num).val())) )
                {
                    rem ++;continue;
//					alert('请填写好数量');
//					return ;
                }
                if(quality_count==0 && bad_id==0)
                {
                    rem ++;continue;
//					alert('新添加的数量不能为0');
//					return ;
                }
                //alert(id_num);return;

                if($(id_way).val()==1000)
                {
                    rem ++;continue;
//					alert('请选择不良品的处理方式');
//					return ;
                }


                if(result=='')
                {
                    rem ++;continue;
//					alert("请你写下备注，以便仓库好操作");
//					return;
                }

                //alert(bad_id);return;
                if(bad_id > 0)
                {
                    k++;
                }
                cou +=parseInt($(id_num).val());
//			var record=new Array();
//			record[0]=quality_count;
//			record[1]=way_zong;
//			record[2]=remark;
                //	alert(quality_count);
                chuli[num] ={"bad_id":bad_id,"quality_count":quality_count,"way_zong":way_zong,"remark":remark,"coupon_price":coupon_price,"return_cost":dan_price};
            }
            if(cou>shu)
            {
                alert("填写不合格的总量已经超出质检出来的不合格量了，请确认");
                return ;
            }

            //var se = new Array();
            var fd ='';
            var fda ='';
            var stamp=0;
            $.ajax({
                type:'post',
                url:'<?php echo url::base(true);?>unqualified/unqualified_check',
                dataType:'json',
                //data:'id='+id+'&fail_deal_way='+way_zong+'&quality_count='+quality_count+'&check_detail_id='+check_detail_id+'&quantity='+shu+'&remark='+remark+'&purchaseorder_id='+purchaseorder_id+'&sku='+sku+'&sku_name='+sku_name+'&vProviderName='+vProviderName,
                data:{'id':id,'chuli':chuli,'check_detail_id':check_detail_id,'vProviderName':vProviderName,'quantity':shu,'purchaseorder_id':purchaseorder_id,'sku':sku,'sku_name':sku_name,'inputs':cou},
                async:false,

                success:function(data)
                {
                    if(data==10){
                        stamp=1;
                        alert('处理错误，实际库存量已改变');return;
                    }
                    //注释了一行
                    //return;
                    if(data.insert)
                    {
//						alert(data.insert.length);return;
                        for(var i=0;i<data.insert.length;i++)
                        {
                            if(data.insert[i] >0)
                            {
                                $("#bad_"+id+'_'+parseInt(1001+k+i+1)).val(data.insert[i]);
                            }
                            else
                            {
                                fd+= parseInt(k+i+1)+',';
                            }
                        }

                    }
                    if(data.update)
                    {
                        for(var n=0;n<data.update.length;n++)
                        {
                            if(data.update[n].update == 0)
                            {
                                fda+= parseInt(n+1) + ',';
                            }

                        }
                    }
                },
                error:function(){
                    alert("错误");exit;
                }
            });
            if(stamp==1){
                return false;
            }
            if(fd)
            {
                alert("第"+fda+"不能更新");

            }
            if(fd)
            {
                alert("第"+fd+"有错误");

            }
            else
            {
                if(rem==0){
                    alert('操作成功');
                }else{
                    alert(wrong_msg+"\n"+chuli.length+'行提交成功,'+'有'+rem+'行未成功提交');
                }
                //注释了两行
                window.location.href=window.location.href;
                window.location.reload;
            }
        });


        $("#supplier_id").keyup(function(e){
            var $val=$(this).val();
            showHint($val);


        });

    });

    //根据供应商名字的一部分文字进行查询
    function showHint(str){
        if(str.length==0){
            $("#supplier_id").val('');
            return false;
        }
        var url="<?php echo URL::base() ?>receipt/select_supplier";
        url+="?name="+str;
        url+="&sid="+Math.random();
        $.getJSON(url,function(data){
            $("#txtHint").html("");
            var $array=data.split(',');
            $.each($array,function(index,value){
                $('<li>'+value+'</li>').appendTo($("#txtHint"));
                $("#txtHint").show();
                $('#txtHint li').click(function(){
                    $("#supplier_id").val($(this).text());
                    $(this).parent().hide();
                });
                $(document).click(function(){
                    $("#txtHint").hide();
                });
            });
        });
    }
    --></script>


<script>
    $(function(){
        $(".su_input").dblclick(function(){
            var un_id = $(this).next("input").val();
            var sku = $("#sku_"+un_id).val();
            var dialog = art.dialog({title: '修改供应商',lock: true, height : "350", width : "300", button: [{
                name: '关闭',
                callback: function () {
                    window.location.reload();

                }}]});
            dialog.content('<p>数据查询中,请稍后...<p>');
            $.get("<?php echo URL::base(true)?>unqualified/change_supplier",
                {"id":un_id,'sku':sku},
                function(view){
                    var view = jQuery.parseJSON(view);
                    dialog.content(view.view);
                });
        });
        $(".pu_man_input").dblclick(function(){
            var un_id = $(this).next("input").val();
            var dialog = art.dialog({title: '修改处理人',lock: true,height : "350", width : "300",button: [{
                name: '关闭',
                callback: function () {
                    window.location.reload();

                }}]});
            dialog.content('<p>数据查询中,请稍后...<p>');
            $.get("<?php echo URL::base(true)?>unqualified/change_pu_man",
                {"id":un_id},
                function(view){
                    var view = jQuery.parseJSON(view);
                    dialog.content(view.view);
                });
        });
        $("#down").click(function(){
            var no_purchaseorder_id=$("select[name='no_purchaseorder_id']").val();
            var purchase_man_name=$("input[name='purchase_man_name']").val();
            var sku=$("input[name='sku']").val();
            var operate_man=$("input[name='operate_man']").val();
            var supplier=$("input[name='supplier']").val();
            var purchaseorder_id=$("input[name='purchaseorder_id']").val();
            var date_from=$("input[name='date_from']").val();
            var date_to=$("input[name='date_to']").val();
            var date_from_c=$("input[name='date_from_c']").val();
            var date_to_c=$("input[name='date_to_c']").val();
            var status=$("#status_choose").val();

            var uri='purchase_man_name='+purchase_man_name+'&sku='+sku+'&operate_man='+operate_man+
                '&supplier='+supplier+'&purchaseorder_id='+purchaseorder_id+'&date_from='+date_from+
                '&date_to='+date_to+'&date_from_c='+date_from_c+'&date_to_c='+date_to_c+
                '&status='+status+'&no_purchaseorder_id='+no_purchaseorder_id;

            window.location.href="<?php echo URL::base()?>handlequality/download?"+uri+'&tableName=unqualified_deal_invoices';
        });
    });
</script>